package com.gthncz.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gthncz.common.CommonResult;
import com.gthncz.mbg.pojo.AuthRoleUser;
import com.gthncz.service.UserService;

@RestController
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/demo", produces = "application/json; charset=UTF-8")
	public CommonResult userList() {
		ArrayList<String> list = new ArrayList<String>() {{
			add("GT");
			add("ZWL");
		}};
		CommonResult result = new CommonResult(200, "OK", list);
		return result;
	}
	
	@RequestMapping(value = "/hello", produces = "application/json; charset=UTF-8")
	public CommonResult hello() {
		ArrayList<String> list = new ArrayList<String>() {{ add("hello~"); }};
		CommonResult result = new CommonResult(200, "OK", list);
		return result;
	}
	
	@RequestMapping(value = "/world", produces = "application/json; charset=UTF-8")
	public CommonResult world() {
		ArrayList<String> list = new ArrayList<String>() {{ add("world~"); }};
		CommonResult result = new CommonResult(200, "OK", list);
		return result;
	}
	
	@RequestMapping(value = "/users", produces = "application/json; charset=UTF-8")
	public CommonResult dbusers() {
		List<AuthRoleUser> dbUsers = userService.listUsers();
		return new CommonResult(200, "OK", dbUsers);
	}

	@RequestMapping(value = "/user/{username}", produces = "application/json; charset=UTF-8")
	public CommonResult getUser(@PathVariable(value = "username", required = true) String username) {
		AuthRoleUser user = userService.findUserByUsername(username);
		return new CommonResult(200, "OK", user);
	}
}
